#ifndef __COMPONENT_LOOT_H__
#define __COMPONENT_LOOT_H__

#include <vector>
#include "Components/Component.hpp"
#include "nlohmann/json.hpp"

namespace PocketSurvival
{
    struct Loot
    {
        // 物品的完整id值
        int32_t blockValue;
        // 最少数量
        int32_t minCount;
        // 最大数量
        int32_t maxCount;
        // 掉落几率
        float probability;

        Loot() = default;
        Loot(int32_t theBlockValue, int32_t theMinCount, int32_t theMaxCount, float theProbability) : 
            blockValue(theBlockValue), 
            minCount(theMinCount), 
            maxCount(theMaxCount),
            probability(theProbability) {}

        friend inline void from_json(const nlohmann::json &json, Loot &loot);
    };

    inline void from_json(const nlohmann::json &json, Loot &loot)
    {
        loot.blockValue = json["BlockValue"].get<int32_t>();
        loot.minCount = json["MinCount"].get<int32_t>();
        loot.maxCount = json["MaxCount"].get<int32_t>();
        loot.probability = json["Probability"].get<float>();
    }


    struct ComponentCreature;

    struct ComponentLoot : public Component
    {
        std::vector<Loot> lootVec;
        std::vector<Loot> lootOnFireVec;
        bool lootDropped;

        ComponentCreature *componentCreature;


        virtual void update(float dt) override;
        virtual const std::string &getName() const override;
        static const std::string &GetName();
        virtual void load(const nlohmann::json &jsonData) override;
        virtual void save(nlohmann::json &jsonData) override;
    };
    
} // namespace PocketSurvival

#endif
